package srv

import (
	"context"
	"net"

	"GrpcPool/pb"

	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
)

const (
	Method = "tcp"
)

type server struct {
}

func (s *server) QueryUser(_ context.Context, _ *pb.UserInfo) (*pb.User, error) {
	return &pb.User{
		Exist: true,
	}, nil
}

func StartGrpcServer(serverSocket string) {
	listener, err := net.Listen(Method, serverSocket)
	if err != nil {
		panic(err)
	}
	s := grpc.NewServer()
	pb.RegisterQueryUserServiceServer(s, &server{})
	reflection.Register(s)
	err = s.Serve(listener)
	if err != nil {
		panic(err)
	}
}
